﻿define(["jquery", "bootstrap", "jquery.fancybox", "jquery.unobtrusive"], function ($) {
    var backToTop = $(".back-to-top");

    var init = function () {
        $.validator.messages.maxlength = "";

        initBackToTopButton();
        initRightSideFloatMenu();
        initTuoGuangToolTip();
    }

    var initTuoGuangToolTip = function () {
        $(".tuo-guang").on("click", function () {
            $.fancybox.open("#tooltipcontent1", {
                closeBtn: false,
                type: 'inline',
                width: 300,
                wrapCSS: 'tooltip-wrap',
                padding: 0
            });
        });
    }

    var initBackToTopButton = function () {

        showBackToTopButton();

        backToTop.click(function () {
            $('html,body').animate({ scrollTop: 0 }, 300); return false;
        });

        $(window).scroll(function () {
            showBackToTopButton();
        });

    }

    var initRightSideFloatMenu = function () {
        $('[data-toggle="tooltip"]').tooltip();
        $('[data-float-menu="true"]').mouseenter(function () {
            var target = $(this).data("target");
            var html = $(target).html();
            var jQTarget = $(html);
            jQTarget.hide();
            $(this).append(jQTarget);
            jQTarget.css("left", -jQTarget.innerWidth());
            jQTarget.fadeIn();
        });

        $('[data-float-menu="true"]').mouseleave(function () {
            $(this).find(".float-menu").remove();
        });

        $("#imgQQ").mouseover(function () {
            $(this).attr("src", "Public/themes/images/qq.gif");
        }).mouseout(function () {
            $(this).attr("src", "Public/themes/images/qq.png");
        });

    }

    var showBackToTopButton = function () {
        var top = $(document).scrollTop();
        if (top > 100) {
            var height = $(window).height();
            backToTop.fadeIn(300).css({
                top: height - 80
            });
        }
        if (top < 100) {
            backToTop.fadeOut(200);
        }
    }

    return {
        init: init
    };
});